package gui;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.layout.VerticalLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.windows.MainWindow;
import org.uqbar.arena.windows.Window;

@SuppressWarnings("serial")
public class PrincipalWindow extends MainWindow<Principal> {

	public PrincipalWindow() {
		super(new Principal());
	}

	@Override
	public void createContents(Panel mainPanel) {
		this.setTitle("Aterrizar.com");

		mainPanel.setLayout(new VerticalLayout());

		Panel welcomePanel = new Panel(mainPanel)
				.setLayout(new HorizontalLayout());

		createWelcomePanel(welcomePanel);

		new Label(mainPanel).setText("¿Que desea Hacer?");

		Panel buttonPanel = new Panel(mainPanel)
				.setLayout(new HorizontalLayout());

		createButtonPanel(buttonPanel);

	}

	private void createWelcomePanel(Panel welcomePanel) {
		new Label(welcomePanel).setText("Hola");

		new Label(welcomePanel).bindValueToProperty("usuario");
	}

	private void createButtonPanel(Panel buttonPanel) {
		new Button(buttonPanel) //
				.setCaption("Ver Compras").onClick(
						new MessageSend(this, "verCompras"));

		new Button(buttonPanel) //
				.setCaption("Ver Reservas").onClick(
						new MessageSend(this, "verReservas"));

		new Button(buttonPanel) //
				.setCaption("Buscar Asientos").onClick(
						new MessageSend(this, "buscarAsientos"));
	}

	public void buscarAsientos() {
		this.openDialog(new BuscadorAsientosWindow(this, getModelObject().getUser()));
	}

	public void verCompras() {
		this.openDialog(new ReservasYComprasAsientosWindow(this,
				new ComprasAsientos(getModelObject().getUser())));
	}

	public void verReservas() {
		this.openDialog(new ReservasYComprasAsientosWindow(this,
				new ReservasAsientos(getModelObject().getUser())));
	}

	protected void openDialog(Window<?> dialog) {
		dialog.open();
	}

	public static void main(String[] args) {
		new PrincipalWindow().startApplication();
	}

}
